package com.lu.library.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.view.Gravity
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.lu.library.R
import com.lu.library.databinding.DialogWheelBinding

/***
 * 带滚轮的弹框
 */
class WheelViewDialog<T>(context: Context,
                         val data:List<T>,
                         var currentIndex:Int,
                         val onSelectedCallback:(Int)->Unit): BottomSheetDialog(context) {


    private lateinit var binding: DialogWheelBinding


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DialogWheelBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.tvCancel.setOnClickListener {
            dismiss()
        }
        binding.wheelView.data = data
        binding.wheelView.setOnItemSelectedListener { picker, data, position ->
            currentIndex = position
        }
        binding.wheelView.setSelectedItemPosition(currentIndex,false)
        binding.tvOk.setOnClickListener {
            onSelectedCallback(currentIndex)
            dismiss()
        }

    }


}